package com.danco.training.zaneuskaya.connection.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.usertype.ParameterizedType;

import com.danco.training.zaneuskaya.domain.Book;

public abstract class AbstractHibernateDao<T, PK extends Serializable> implements
		GenericDao<T, PK> {
	
	
	public void create(Session session, T object) throws HibernateException {
	
		 session.saveOrUpdate(object);
		
	}

	@SuppressWarnings("unchecked")
	public T read(Session session,Class cl, Integer PK) throws HibernateException {
			return (T) session.get(cl, PK);	
		
	}

	
	
	public List<T> readAll(Class cl,Session session) throws HibernateException {
			Criteria crit = session.createCriteria(cl);
			return ( List<T>) crit.list();
	}

	
	public void update(Session session, T object) throws HibernateException {
		session.update(object);
	}

	@Override
	public void delete(Session session, T object) throws HibernateException {
         session.delete(object);

	}
	
	

}
